<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>hrtfstat</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="hrtfreverb.html" title="hrtfreverb" />
    <link rel="next" href="hsboscil.html" title="hsboscil" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">hrtfstat</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="hrtfreverb.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="hsboscil.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="hrtfstat"></a>
      <div class="titlepage"></div>
      <a id="IndexHrtfstat" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">hrtfstat</span>
        </h2>
        <p>hrtfstat — 
      Generates static 3d binaural audio for headphones using a
      Woodworth based spherical head model with improved low frequency
      phase accuracy.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp114586768"></a>
        <h2>Description</h2>
        <p>
      This opcode takes a source signal and spatialises it in the 3 dimensional space around a listener using head related transfer function (HRTF) based filters. It produces a static output (azimuth and elevation parameters are i-rate), because a static source allows much more efficient processing than <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a> and <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>,. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp114590160"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">
      aleft, aright <span class="command"><strong>hrtfstat</strong></span> asrc, iAz, iElev, ifilel, ifiler [,iradius, isr]
    </pre>
      </div>
      <div class="refsect1">
        <a id="idp114592400"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iAz</em></span> -- azimuth value in degrees. Positive
      values represent position on the right, negative values are
      positions on the left. 
    </p>
        <p>
      <span class="emphasis"><em>iElev</em></span> -- elevation value in
      degrees. Positive values represent position above horizontal,
      negative values are positions below horizontal (min -40). 
    </p>
        <p>
      <span class="emphasis"><em>ifilel </em></span> -- left HRTF spectral data file
    </p>
        <p>
      <span class="emphasis"><em>ifiler </em></span> -- right HRTF spectral data file
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        Spectral datafiles (based on the MIT
        HRTF database) are available in 3 different sampling rates:
        44.1, 48 and 96 khz and are labelled accordingly. Input and
        processing sr should match datafile sr. Files should be in the
        current directory or the SADIR (see <a class="link" href="CommandEnvironment.html" title="Csound Environment Variables"><em class="citetitle">Environment Variables</em></a>).
      </p>
              </td>
            </tr>
          </table>
        </div>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
       HRTF Data files for use with 
      <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a>,
      <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>,
      <a class="link" href="hrtfstat.html" title="hrtfstat"><em class="citetitle">hrtfstat</em></a>,
      <a class="link" href="hrtfearly.html" title="hrtfearly"><em class="citetitle">hrtfearly</em></a>,
      <a class="link" href="hrtfreverb.html" title="hrtfreverb"><em class="citetitle">hrtfreverb</em></a>
       were updated for Csound 5.15 and later (the code was updated and is more efficient). Old datafiles are now deprecated.
      </p>
              </td>
            </tr>
          </table>
        </div>
        <p>
      <span class="emphasis"><em>iradius</em></span> --  optional, head radius used for
      phase spectra calculation in centimeters (default 9.0)
    </p>
        <p>
      <span class="emphasis"><em>isr</em></span> - optional (default 44.1kHz). Legal
      values are 44100, 48000 and 96000.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp114606320"></a>
        <h2>Performance</h2>
        <p>
      Artifact-free user-defined static spatialisation is made
      possible using an interpolation algorithm based on spectral
      magnitude interpolation and a derived phase based on the
      Woodworth spherical head model.
      Accuracy is increased for the data set provided by extracting
      and applying a frequency dependent scaling factor to the phase
      spectra, leading to a more precise low frequency interaural time
      difference.
      Users can control head radius for the phase derivation, allowing
      a crude level of individualisation.
      The static source version of the opcode uses overlap add
      convolution (it does not need STFT processing, see <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>),
      and is thus considerably more efficient than <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a> or
      <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a>, but cannot generate moving sources. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp114611152"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the hrtfstat opcode. It uses the file <a class="ulink" href="examples/hrtfstat.csd" target="_top"><em class="citetitle">hrtfstat.csd</em></a>. 
    </p>
        <div class="example">
          <a id="idp114613136"></a>
          <p class="title">
            <strong>Example 372. Example of the hrtfstat opcode.
      </strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac      <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o hrtfstat.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1
    
gasrc <span class="opc">init</span> 0

<span class="oblock">instr</span> 1	<span class="comment">;a plucked string</span>

kamp <span class="op">=</span> p4
kcps <span class="op">=</span> <span class="opc">cpspch</span>(p5)
icps <span class="op">=</span> <span class="opc">cpspch</span>(p5)
a1 <span class="opc">pluck</span> kamp, kcps, icps, 0, 1

gasrc <span class="op">=</span> a1

<span class="oblock">endin</span>

<span class="oblock">instr</span> 10<span class="comment">;uses output from instr1 as source</span>

aleft,aright <span class="opc">hrtfstat</span> gasrc, 90,0, "hrtf<span class="op">-</span>44100<span class="op">-</span>left.dat","hrtf<span class="op">-</span>44100<span class="op">-</span>right.dat"
             <span class="opc">outs</span>     aleft, aright

<span class="opc">clear</span> gasrc
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span>1 0 2 .7 8.00	<span class="comment">; Play Instrument 1: a plucked string</span>
<span class="stamnt">i</span>1 .5 2 .7 8.00
<span class="stamnt">i</span>1 1 2 .7 8.00
<span class="stamnt">i</span>1 2 2 .7 7.00

<span class="stamnt">i</span>10 0 12	<span class="comment">; Play Instrument 10 for 2 seconds.</span>

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <br class="example-break" />
        <p>
      Here is another example of the hrtfstat opcode. It uses the file <a class="ulink" href="examples/hrtfstat-2.csd" target="_top"><em class="citetitle">htrfstat-2.csd</em></a>, and <a class="ulink" href="examples/Church.wav" target="_top"><em class="citetitle">Church.wav</em></a>, which is a looped sample.

      </p>
        <div class="example">
          <a id="idp114619168"></a>
          <p class="title">
            <strong>Example 373. Example two of the hrtfstat opcode</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o hrtfstat-2.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1

iAz   <span class="op">=</span> p4
iElev <span class="op">=</span> p5

itim <span class="op">=</span> <span class="opc">ftlptim</span>(1)
<span class="comment">;    transeg a   dur   ty  b  dur    ty  c    dur   ty  d</span>
kamp <span class="opc">transeg</span> 0, p3<span class="op">*</span>.1, 0, .9, p3<span class="op">*</span>.3, <span class="op">-</span>3, .5,  p3<span class="op">*</span>.3, <span class="op">-</span>2, 0
ain  <span class="opc">loscil3</span> kamp, 50, 1
aleft,aright <span class="opc">hrtfstat</span> ain, iAz, iElev, "hrtf<span class="op">-</span>44100<span class="op">-</span>left.dat","hrtf<span class="op">-</span>44100<span class="op">-</span>right.dat"
     <span class="opc">outs</span> aleft, aright

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span> 1 0 0 1 "Church.wav" 0 0 0 <span class="comment">;Csound computes tablesize</span>

<span class="comment">;      Azim Elev</span>
<span class="stamnt">i</span>1 0 7  90   0  <span class="comment">;to the right</span>
<span class="stamnt">i</span>1 3 7 -90  -40 <span class="comment">;to the left and below</span>
<span class="stamnt">i</span>1 6 7 180   90 <span class="comment">;behind and up</span>
<span class="stamnt">e</span> 
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp114621088"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="hrtfmove.html" title="hrtfmove"><em class="citetitle">hrtfmove</em></a>,
      <a class="link" href="hrtfmove2.html" title="hrtfmove2"><em class="citetitle">hrtfmove2</em></a>,
      <a class="link" href="hrtfer.html" title="hrtfer"><em class="citetitle">hrtfer</em></a>.
    </p>
        <p> More information on this opcode: <a class="ulink" href="http://www.csoundjournal.com/issue9/newHRTFOpcodes.html" target="_top"><em class="citetitle">http://www.csoundjournal.com/issue9/newHRTFOpcodes.html</em></a>  , written by Brian Carty </p>
      </div>
      <div class="refsect1">
        <a id="idp114626448"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Brian Carty</td>
          </tr>
          <tr>
            <td>Maynooth</td>
          </tr>
          <tr>
            <td>2008</td>
          </tr>
        </table>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="hrtfreverb.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="hsboscil.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">hrtfreverb </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> hsboscil</td>
        </tr>
      </table>
    </div>
  </body>
</html>
